package Year22_Month01.day0106;


public class Solution {
    //203.移除链表元素
    public ListNode remove(ListNode head,int val){
        ListNode cur = null;
        ListNode key = cur;
        cur.next = head;
        while(cur != null) {
            if (cur.next.val == val) {
                cur.next = cur.next.next;
            }
            cur = cur.next;
        }
        return key.next;
    }

    //206.反转链表
    public ListNode reverselist(ListNode head){
        ListNode slow = head;//定义当前指针
        ListNode fast = null;//定义快指针
        ListNode time = null;//定义临时指针
        while(slow != null){
            fast = slow.next;
            slow.next = time;
            time = slow;
            slow = fast;
        }
        return slow;
    }
}
